<template>
  <div class="into">
    <div class="into_header">
      <top-bar :barObj="barObj"/>
      <div class="erCode">
        <div id="qrcode"></div>
        <!-- <img src="./img/Figure.png" alt> -->
      </div>
    </div>
    <div class="content">
      <div class="key">游戏ID</div>
      <div class="val">{{userData.GameID}}</div>
      <div class="key">地址</div>
      <div class="val address">{{userData.BlockCAddress}}</div>
      <div
        class="btn"
        v-clipboard:copy="userData.BlockCAddress"
        v-clipboard:success="onCopy"
        v-clipboard:error="onError"
      >复制地址</div>
      <div class="yeluosen"></div>
    </div>
  </div>
</template>
<script>
import topBar from "@/components/topBar";
import QRCode from "qrcodejs2";
import { Toast } from "mint-ui";
import { getUserInfo } from "../../api.js";
import { getGuid } from "../../utils/index";

export default {
  name: "into",
  data() {
    return {
      barObj: {
        isBack: true,
        backVal: "钱包",
        title: "转入",
        isIcon: true
      },
      userData: {}
    };
  },
  components: {
    topBar
  },
  mounted() {
    let id = localStorage.zyUserId;
    getUserInfo({
      ID: id,
      LoginMachine: getGuid()
    }).then(res => {
      if (res.data.Success) {
        this.userData = res.data.EntityList[0];
        this.qrcodeScan();
      } else {
        Toast({
          message: res.data.Content,
          duration: 3000
        });
        // this.$router.push("/login");
      }
    });
  },
  methods: {
    onCopy: function(e) {
      console.log(e);
      Toast({
        message: "复制成功",
        duration: 3000
      });
    },
    onError: function(e) {
      Toast({
        message: "复制失败！",
        duration: 3000
      });
    },

    qrcodeScan() {
      //生成二维码
      let qrcode = new QRCode("qrcode", {
        width: 150, // 二维码宽度
        height: 150, // 二维码高度
        text: this.userData.BlockCAddress
      });
    }
  }
};
</script>
<style lang="stylus" scoped>
.into {
  width: 100%;

  .into_header {
    height: 6.39rem;
    padding-top: 0.52rem;
    box-sizing: border-box;
    background: linear-gradient(90deg, rgba(0, 174, 255, 1), rgba(0, 180, 255, 1), rgba(0, 120, 255, 1));
    position: relative;

    .erCode {
      width: 3.98rem;
      height: 3.98rem;
      border-radius: 0.3rem;
      background: #FFF;
      margin: 20px auto;
      position: relative;

      // position: absolute;
      // left: 50%;
      // transform: translateX(-50%);
      #qrcode {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      }

      img {
        width: 3rem;
        height: 3rem;
        margin: 0 auto;
      }
    }
  }

  .content {
    width: 7.07rem;
    height: 7.11rem;
    background: #FFF;
    border-radius: 10px;
    margin: 0 auto;
    padding: 25px;
    box-sizing: border-box;
    position: relative;
    top: -25px;

    .btn {
      color: #fff;
      background: rgba(16, 137, 255, 1);
      text-align: center;
      width: 2.01rem;
      line-height: 0.6rem;
      background: rgba(0, 120, 255, 1);
      border-radius: 0.2rem;
      margin: 20px auto;
    }

    .key {
      color: #006AEE;
      font-size: 16px;
      line-height: 0.7rem;
    }

    .val {
      font-size: 20px;
      line-height: 0.7rem;
    }

    .address {
      width: 100%;
      display: inline-block;
      background: #E8E8E8;
      border-radius: 10px;
      padding: 0 5px;
      box-sizing: border-box;
      word-wrap: break-word;
      // overflow: hidden;
    }
  }
}
</style>

